import {
  registerMicroApps,
  initGlobalState,
  start
  // setDefaultMountApp
} from "qiankun";

const getActiveRule = hash => location => {
  return location.hash.startsWith(hash);
};

import render from "@/render/VueRender";

import store from "@/store";

render({ loading: false });

const loader = loading => render({ loading });

export const microList = [
  {
    name: "pureHtml",
    entry:
      process.env.NODE_ENV === "production"
        ? "/app/pureHtml/"
        : "//localhost:9001/",
    container: "#container",
    loader,
    activeRule: getActiveRule("#/pureHtml")
  },
  {
    name: "vueChild",
    entry:
      process.env.NODE_ENV === "production"
        ? "/app/vue-child/"
        : "//localhost:9000/app/vue-child/",
    container: "#container",
    loader,
    activeRule: getActiveRule("#/app-vue-hash"),
    props: {
      store,
      test: () => {
        console.log("vueChild");
      },
      name: "vueChild"
    }
  }
];
registerMicroApps([]);

let state = {
  name: "啥子",
  age: 20,
  headImg: ""
};

const actions = initGlobalState(state);

actions.onGlobalStateChange((state, prev) => {
  console.log(state, prev);
});
actions.setGlobalState({ ...state, age: 21 });

// if (!location.hash) {
//   setDefaultMountApp("#/pureHtml");
// }

start({
  // 低版本浏览器开启沙箱 Can't find variable: MutationObserver
  // sandbox: {
  //   // strictStyleIsolation: true,
  //   experimentalStyleIsolation: true
  // }
});
